﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace TestModule
{
    public partial class TestForm : Form
    {
        public TestForm()
        {
            InitializeComponent();
            InitialTestInterface();
            InitialDrawTool();
        }

        #region 测试接口引入
        private ITestInterface _iTest = null;
        private void InitialTestInterface()
        {
            this._iTest = new TestBaseMethod();
        }
        #endregion

        #region 绘图面板
        private DrawTool _drawTool = null;
        private void InitialDrawTool()
        {
            this._drawTool = new DrawTool(this.panel1.CreateGraphics());
            this._drawTool.CurveSet = this._iTest.GetCurveSet();
        }
        #endregion

        private void 显示ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (this._drawTool == null)
                return;
            
            this._drawTool.DrawGraphic();
        }

        private void 放大ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this._drawTool.ClearGraphic();
            this._drawTool.WidenGraphic(1.1f);
            this._drawTool.DrawGraphic();
        }

        private void 缩小ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this._drawTool.ClearGraphic();
            this._drawTool.WidenGraphic(0.9f);
            this._drawTool.DrawGraphic();
        }

        #region 测量
        private int _bMeasure = 0;
        private Point _measureBeginPoint = new Point() { X = 0, Y = 0};
        private void 测量ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this._bMeasure = 1;
        }

        private void panel1_MouseDown(object sender, MouseEventArgs e)
        {
            if (_bMeasure == 1)
            {
                _measureBeginPoint = new Point { X = e.X, Y = e.Y };
                _bMeasure++;
            }
            else if (_bMeasure == 2)
            {
                MessageBox.Show((Math.Sqrt(Math.Pow((e.X - _measureBeginPoint.X), 2) + Math.Pow((e.Y - _measureBeginPoint.Y), 2))).ToString());
                _bMeasure = 0;
            }
        }
        #endregion

        private void toolStripMenuItem2_Click(object sender, EventArgs e)
        {
            this._drawTool.ClearGraphic();
            this._drawTool.SetPointSymbol(PointType.STAR_POINT);
            this._drawTool.DrawGraphic();
        }

        private void toolStripMenuItem3_Click(object sender, EventArgs e)
        {
            this._drawTool.ClearGraphic();
            this._drawTool.SetPointSymbol(PointType.RECT_POINT);
            this._drawTool.DrawGraphic();
        }

        private void toolStripMenuItem4_Click(object sender, EventArgs e)
        {
            this._drawTool.ClearGraphic();
            this._drawTool.SetPointSymbol(PointType.ARC_POINT);
            this._drawTool.DrawGraphic();
        }

        private void toolStripMenuItem5_Click(object sender, EventArgs e)
        {
            this._drawTool.ClearGraphic();
            this._drawTool.SetPointSymbol(PointType.NORMAL_POINT);
            this._drawTool.DrawGraphic();
        }

        private bool bPointRemark = true;
        private void 标签ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            bPointRemark = bPointRemark == true ? false : true;
            this._drawTool.ClearGraphic();
            this._drawTool.SetBPointRemark(this.bPointRemark, typeof(NodePoint));
            this._drawTool.DrawGraphic();
        }

        private float _lineWidth = 1;
        private void toolStripMenuItem13_Click(object sender, EventArgs e)
        {
            this._lineWidth = this._lineWidth + Convert.ToSingle(0.20);
            this._drawTool.ClearGraphic();
            this._drawTool.SetLineSymbolWidth(this._lineWidth);
            this._drawTool.DrawGraphic();
        }

        private void toolStripMenuItem14_Click(object sender, EventArgs e)
        {
            this._lineWidth = this._lineWidth - Convert.ToSingle(0.20);
            this._drawTool.ClearGraphic();
            this._drawTool.SetLineSymbolWidth(this._lineWidth);
            this._drawTool.DrawGraphic();
        }

        private bool bPointIndex = false;
        private void 编号ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            bLineIndex = bLineIndex == true ? false : true;
            this._drawTool.ClearGraphic();
            this._drawTool.SetIndex(this.bLineIndex, typeof(NodeLineSymbol));
            this._drawTool.DrawGraphic();
        }

        private bool bLineIndex = false;
        private void 编号ToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            bPointIndex = bPointIndex == true ? false : true;
            this._drawTool.ClearGraphic();
            this._drawTool.SetIndex(this.bPointIndex, typeof(NodePoint));
            this._drawTool.DrawGraphic();
        }

        private void 红色ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this._drawTool.ClearGraphic();
            this._drawTool.SetLineSymbolColor(Color.Red);
            this._drawTool.DrawGraphic();
        }

        private void 黑色ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this._drawTool.ClearGraphic();
            this._drawTool.SetLineSymbolColor(Color.Black);
            this._drawTool.DrawGraphic();
        }
    }
}
